# ----------------------------------------------------------------------------
#   ERRightMousePan.rb  Right Mouse Panning
# ----------------------------------------------------------------------------
# Turn a dragging RightMouseDown into a camera dolly
#

require "sketchup.rb"
require "EventRelay.dll"

# ----------------------------------------------------------------------------
class RightMousePan < EventRelay
# ----------------------------------------------------------------------------

    SUPPRESS = true
    ALLOW = false

    # ----------------------------------
    #    initialize
    # ----------------------------------
    def initialize
        super
        @cameraDolly = false
    end
    # ----------------------------------
    #    Mouse OnRButtonUp
    # ----------------------------------
    def OnRButtonUp(flags, x, y)
        #- puts "ON RIGHT BUTTON UP flags:#{flags} x:#{x} y:#{y}"

        # Release the Camera Dolly after RMouseButton dragging
        if ( @cameraDolly )
            @cameraDolly = false
            SendKeyMacro("{MBUTTON UP}{LSHIFT UP}")
            return SUPPRESS
        end
        return ALLOW
    end #OnRButtonUp
    # ----------------------------------
    #    Mouse OnRButtonDown
    # ----------------------------------
    def OnRButtonDown(flags, x, y)
        #-puts "ON R BUTTON DOWN flags:#{flags} x:#{x} y:#{y}"

        # Right Mouse dragging == Pan (Hand tool)
        # If mouse is dragging after 200 milliseconds, turn on Pan tool
        # and throw away the Right Mouse Down event.
        x1, y1 = GetMousePosition()
        sleep(0.200)
        x2, y2 = GetMousePosition()
        if ( ((x2-x1).abs > 2) or ((y2-y1).abs > 2) )
            #- puts "ON R BUTTON DOWN Mouse is DRAGGING"
            SendKeyMacro( "{LSHIFT DOWN}{MBUTTON DOWN}" )
            @cameraDolly = true
            return SUPPRESS
        end
        return ALLOW
    end #OnRButtonDown

end # class RightMousePan
# ----------------------------------------------------------------------------

unless file_loaded?("ERRightMousePan.rb")
    myRightMousePan = RightMousePan.new
    file_loaded "ERRightMousePan.rb"
end

